package ar.com.spsolutions.splibrary.examplebd;

import org.joda.time.DateTime;

import ar.com.spsolutions.splibrary.book.BookCopy;
import ar.com.spsolutions.splibrary.book.LoanBook;
import ar.com.spsolutions.splibrary.book.LoanBookBuilder;
import ar.com.spsolutions.splibrary.library.Library;
import ar.com.spsolutions.splibrary.notifiers.INotifier;
import ar.com.spsolutions.splibrary.services.AuthorService;
import ar.com.spsolutions.splibrary.services.EntityService;
import ar.com.spsolutions.splibrary.services.RoleService;
import ar.com.spsolutions.splibrary.services.UserService;
import ar.com.spsolutions.splibrary.user.User;
import ar.com.spsolutions.splibrary.user.role.UserRole;

public class DataBasePopulator {
	public void populate(final INotifier notifier,
			final UserService userService, final RoleService roleService,
			final EntityService generalService,
			final AuthorService authorService) {
		final Library library = Library.initialize(notifier);
		final User user = library.getUser();
		userService.add(user);
		roleService.add(UserRole.customer());
		roleService.add(UserRole.librarian());
		final BookCopy copy = BookBD.bookBD(generalService, authorService);
		final LoanBook loan = new LoanBookBuilder()//
				.withUser(user)//
				.withRefunDate(new DateTime().minusDays(10))//
				.withExpirationDate(new DateTime().minusDays(5))//
				.withCopy(copy)//
				.build();
		generalService.getLoanBookService().add(loan);
	}

}
